class Repeat(object):
    """
    The idea of this class is to store how an event repeats.
    It needs to be in a form that can easily be stored as a string
    in an xml file and be easy to work with.
    So, this class will contain a series of variables,
    year, month, week, day, etc... that are all integers.
    0 means that it doesn't matter. 1 means that it does.
    There is also a frequency variable for each type of date increment.
    0 corresponds to variable that does not matter. If it is something else,
    it will effect everything below it. For example, if some event occurs every
    week every other month, the 'month' variable would be set to 0, but the
    repition would be set to 1. The default value for a frequency variable is
    0, which means it repeats normally. If it is one, it is every 2 weeks,
    etc... I figured it makes more sense in terms of the overall mechanism to
    start at 0. 
    """
    def __init__(self, year = 0, yearFreq = 0, month = 0, monthFreq = 0,
                 week = 0, weekFreq = 0, sunday = 0, sundayFreq = 0,
                 monday = 0, mondayFreq = 0, tuesday = 0, tuesdayFreq = 0,
                 wednesday = 0, wednesdayFreq = 0, thursday = 0,
                 thursdayFreq = 0, friday = 0, fridayFreq = 0, saturday = 0,
                 saturdayFreq = 0, endDate=0):
        self.year = year
        self.yearFreq = yearFreq
        self.month. = month
        self.monthFreq = monthFreq
        self.week = week
        self.weekFreq = weekFreq
        self.sunday = sunday
        self.sundayFreq = sundayFreq
        self.monday = monday
        self.mondayFreq = mondayFreq
        self.tuesday = tuesday
        self.tuesdayFreq = tuesdayFreq
        self.wednesday = wednesday
        self.wednesdayFreq = wednesdayFreq
        self.thursday = thursday
        self.thursdayFreq = thursdayFreq
        self.friday = friday
        self.fridayFreq = fridayFreq
        self.saturday = saturday
        self.saturdayFreq = saturdayFreq
        self.endDate= endDate

    def __str__(self):
        formatTuple = (year, yearFreq, month, monthFreq, week, weekFreq, sunday, sundayFreq, monday,
                       mondayFreq, tuesday, tuesdayFreq, wednesday, wednesdayFreq, thursday, thursdayFreq,
                       friday, fridayFreq, saturday, saturdayFreq, endDate)
        return "%i:%i,%i:%i,%i:%i,%i:%i,%i:%i,%i:%i,%i:%i,%i:%i,%i:%i,%i:%i;%i" % formatTuple

    def makeRepeatFromString(cls, repeatString):
        repeatInfo, endDate = repeatString.split(";")
        repeatInfoList      = repeatInfo.split(",")
        argList = []
        for pair in repeatInfoList:
            first, second = pair.split(":")
            argList.append(first)
            argList.append(second)
        argList.append(endDate)
        return eval("cls%t" % tuple(argList))
    makeRepeatFromString = classmethod(makeRepeatFromString)
